-
Notifications
You must be signed in to change notification settings - Fork 230
Protect unit summary and unit locations plots against NaNs #4128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into this error
Traceback (most recent call last):
File "/home/saleem_lab/si_edd/SI_processing/runSpikeSorting.py", line 123, in <module>
export_report(sorting_analyzer=probe_we_ks4, output_folder=save_folder +'probe'+str(probe)+'/sorters/kilosort4/report/')
File "/home/saleem_lab/anaconda3/envs/siedd_env/lib/python3.11/site-packages/spikeinterface/exporters/report.py", line 144, in export_report
sw.plot_unit_summary(sorting_analyzer, unit_id, figure=fig)
File "/home/saleem_lab/anaconda3/envs/siedd_env/lib/python3.11/site-packages/spikeinterface/widgets/unit_summary.py", line 82, in __init__
BaseWidget.__init__(self, plot_data, backend=backend, **backend_kwargs)
File "/home/saleem_lab/anaconda3/envs/siedd_env/lib/python3.11/site-packages/spikeinterface/widgets/base.py", line 87, in __init__
self.do_plot()
File "/home/saleem_lab/anaconda3/envs/siedd_env/lib/python3.11/site-packages/spikeinterface/widgets/base.py", line 108, in do_plot
func(self.data_plot, **self.backend_kwargs)
File "/home/saleem_lab/anaconda3/envs/siedd_env/lib/python3.11/site-packages/spikeinterface/widgets/unit_summary.py", line 172, in plot_matplotlib
UnitWaveformDensityMapWidget(
File "/home/saleem_lab/anaconda3/envs/siedd_env/lib/python3.11/site-packages/spikeinterface/widgets/unit_waveforms_density_map.py", line 87, in __init__
bins = np.arange(bin_min, bin_max, bin_size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: arange: cannot compute length
replacing (lines 85, 86) didn't solve the issue.
#bin_min = np.min(templates) * 1.3
#bin_max = np.max(templates) * 1.3
bin_min = np.nanmin(templates) * 1.3
bin_max = np.nanmax(templates) * 1.3
bin_size = (bin_max - bin_min) / 100
bins = np.arange(bin_min, bin_max, bin_size)
but gave:
File "/home/saleem_lab/anaconda3/envs/siedd_env/lib/python3.11/site-packages/spikeinterface/widgets/unit_waveforms_density_map.py", line 90, in __init__
bin_size = (bin_max - bin_min) / 100
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: arange: cannot compute length
I saw there are some empty entries in the templates metrics csv, not sure if this is linked

Unfortunately, the way my code is factored makes this a bit painful to debug quickly
| extremum_channel_indices = get_template_extremum_channel(sorting_analyzer, outputs="index") | ||
| for unit_id in unit_ids: | ||
| if np.any(np.isnan(unit_locations[unit_id])): | ||
| unit_locations[unit_id] = channel_locations[extremum_channel_indices[unit_id]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make a copy of unit_locaions in this case to avoid inplace replacement in the analyzer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already a copy since we use the by_unit: https://github.com/SpikeInterface/spikeinterface/blob/main/src/spikeinterface/postprocessing/unit_locations.py#L126-L133
Fixes #2844
@eabhorrocks @meszena could you test this out when you get the chance?